<template>
  <div class="app-container">
    <div v-if="params.amountType == 4">
      <h5 class="titleInfo">金币汇总</h5>
      <el-form class="form" ref="form"  label-width="130px">
        <el-table :data="tableData" :summary-method="getSummaries" show-summary>
          <el-table-column prop="applySn" align="center" label="补贴单号"></el-table-column>
          <el-table-column prop="surplusMoney" align="center" label="金币数量"></el-table-column>

          <el-table-column prop="createTime" align="center" label="创建时间"></el-table-column>
        </el-table>
      </el-form>
    </div>

    <div class="divBar"></div>
    <h5 class="titleInfo">{{title}}</h5>
    <el-table :data="tableData2" style="width: 100%">
      <el-table-column prop="realname" align="center" label="姓名"></el-table-column>
      <el-table-column prop="amount" align="center" :label="params.amountType=='1,2'?'银币':'金币'"></el-table-column>
      <el-table-column
        prop="coinDescription"
        align="center"
        :label="params.amountType=='1,2'?'银币说明':'金币说明'"
      ></el-table-column>
      <el-table-column prop="operationInfo" align="center" label="操作信息"></el-table-column>
      <el-table-column prop="remark" align="center" label="备注信息"></el-table-column>
      <el-table-column prop="createTime" align="center" label="创建时间"></el-table-column>
    </el-table>
    <div class="block" style="margin: 40px 0;">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="params.pageNum"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="params.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      ></el-pagination>
    </div>
  </div>
</template>
<script>
import vipmange from "@/api/vipmange/vipmange";
export default {
  data() {
    return {
      tableData: [],
      tableData2: [],
      total: 0,
      title: "金币明细",
      params: {
        pageNum: 1,
        pageSize: 20,
        userId: null,
        amountType: null
      }
    };
  },
  mounted() {
    console.log(this.$route);
    this.params.amountType = this.$route.query.amountType;
    this.params.userId = this.$route.query.iconsId;
    console.log(this.$route.query.amountType == "3");
    if (this.$route.query.amountType == "1,2") {
      this.title = "银币明细";
    }
    if (this.$route.query.amountType == "3") {
      this.title = "金币明细";
    }
    if (this.$route.query.amountType == "4") {
      this.getWaitCreditList();
    }
    this.downlist();
  },
  methods: {
    getSummaries(param) {
      const { columns, data } = param;
      const sums = [];
      columns.forEach((column, index) => {
        if (index === 0) {
          sums[index] = "总价";
          return;
        }

        console.log(columns);
        let surplusMoney = 0;
        data.map(res => {
          surplusMoney += res.surplusMoney - 0;
        });
        switch (column.property) {
          case "surplusMoney":
            sums[index] = surplusMoney;
            break;
          default:
            break;
        }
      });
      return sums;
    },
    async getWaitCreditList() {
      let res = await vipmange.getWaitCreditList({
        userId: this.params.userId
      });
      if (res.data.code == 0) {
        this.tableData = res.data.data.allowanceApplyList;
      } else {
        this.$message({
          message: res.data.msg,
          type: "warning"
        });
      }
    },
    async downlist() {
      let res = await vipmange.iconslist(this.params);
      if (res.data.code == 0) {
        this.tableData2 = res.data.data.list;
        this.total = res.data.data.count;
      } else {
        this.$message({
          message: res.data.msg,
          type: "warning"
        });
      }
    },
    handleSizeChange(val) {
      this.params.pageNum = 1;
      this.params.pageSize = val;
      this.downlist();
    },
    handleCurrentChange(val) {
      this.params.pageNum = val;
      this.downlist();
    }
  }
};
</script>
